<?php

/**
 * click actions.
 *
 * @package    25Mails
 * @subpackage click
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class clickActions extends sfActions {
    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeRedirect(sfWebRequest $request) {
        $linkId = $request->getParameter('lid');
        $recipientId = $request->getParameter('rid');
        $campaignId = $request->getParameter('cid');
        $link = Doctrine_Core::getTable('Link')->findOneByLinkId($linkId);
        if($link != null) { //if the linkId is correct I track the click
            // if cid == 0 then the click was done on a test mail, so I don't track it
            if ($campaignId) {
                $click = new Click();
                $click->setLinkId($linkId);
                $click->setRecipientId($recipientId);
                $click->setCampaignId($campaignId);
                $click->save();
            }
            // than I recdirect to the target URL
            $targetUrl = $link->getTargetUrl();
            $this->redirect($targetUrl);
        }else { //else I show an error
            $this->setLayout('emptylayout');
            $this->setTemplate('wronglink');
        }
    }
}
